﻿/*
' Copyright (c) 2013  Christoc.com
'  All rights reserved.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 
*/

using System;
using System.Net.Mail;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using GP_Hosting_ContactForm;


namespace GP_Hosting_ContactForm
{
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The Settings class manages Module Settings
    /// 
    /// Typically your settings control would be used to manage settings for your module.
    /// There are two types of settings, ModuleSettings, and TabModuleSettings.
    /// 
    /// ModuleSettings apply to all "copies" of a module on a site, no matter which page the module is on. 
    /// 
    /// TabModuleSettings apply only to the current module on the current page, if you copy that module to
    /// another page the settings are not transferred.
    /// 
    /// If you happen to save both TabModuleSettings and ModuleSettings, TabModuleSettings overrides ModuleSettings.
    /// 
    /// Below we have some examples of how to access these settings but you will need to uncomment to use.
    /// 
    /// Because the control inherits from GP_Hosting_ContactFormSettingsBase you have access to any custom properties
    /// defined there, as well as properties from DNN such as PortalId, ModuleId, TabId, UserId and many more.
    /// </summary>
    /// -----------------------------------------------------------------------------
    public partial class Settings : GP_Hosting_ContactFormModuleSettingsBase
    {
    

      

        private string _smtpserver;
        public string SMTPServerSettings
        {
            get
            {
                _smtpserver = string.Empty;
                if (Settings.Contains("SMTPServer"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SMTPServer"].ToString()))
                    {
                        _smtpserver = Settings["SMTPServer"].ToString();
                    }
                }
               return _smtpserver;
            }
            set { _smtpserver = value; }
        }
        private bool _usednnsettings;
        public bool UseDnnSettings
        {
            get
            {
                _usednnsettings = false;

                if (Settings.Contains("DNNSMTPServer"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["DNNSMTPServer"].ToString()))
                    {
                        bool.TryParse(Settings["DNNSMTPServer"].ToString(), out _usednnsettings);
                    }
                }
                return _usednnsettings;
            }
            set { _usednnsettings = value; }
        }
        private string _smtpusername;
        public string SmtpUsername
        {
            get
            {
                _smtpusername = string.Empty;
                if (Settings.Contains("SMTPUsername"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SMTPUsername"].ToString()))
                    {
                        _smtpusername = Settings["SMTPUsername"].ToString();
                    }
                }
                return _smtpusername;
            }
            set { _smtpusername = value; }
        }
        private string _smtppassword;
        public string SmtpPassword
        {
            get
            {
                _smtppassword = string.Empty;
                if (Settings.Contains("SMTPPassword"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SMTPPassword"].ToString()))
                    {
                        _smtppassword = Settings["SMTPPassword"].ToString();
                    }
                }
                
                return _smtppassword;
            }
            set { _smtppassword = value; }
        }
        private string _smtpportnum;
        public string SmtpPortnum
        {
            get
            {
                _smtpportnum = string.Empty;
                if (Settings.Contains("SMTPPort"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SMTPPort"].ToString()))
                    {
                        _smtpportnum = Settings["SMTPPort"].ToString();
                    }
                }
                return _smtpportnum;
            }
            set { _smtpportnum = value; }
        }
        private string _toaddress;
        public string GetToAddress
        {
            get
            {
                _toaddress = string.Empty;
                if (Settings.Contains("ToAddress"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ToAddress"].ToString()))
                    {
                        _toaddress = Settings["ToAddress"].ToString();
                    }
                }
                
                return _toaddress;
            }
            set { _toaddress = value; }
        }
        private string _fromaddress;
        public string GetFromAddress
        {
            get
            {
                _fromaddress = string.Empty;
                if (Settings.Contains("FromAddress"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["FromAddress"].ToString()))
                    {
                        _fromaddress = Settings["FromAddress"].ToString();
                    }
                }
                return _fromaddress;
            }
            set { _fromaddress = value; }
        }
        private string _emailsubject;
        public string GetEmailsubject
        {
            get
            {
                _emailsubject = string.Empty;
                if (Settings.Contains("Subject"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["Subject"].ToString()))
                    {
                        _emailsubject = Settings["Subject"].ToString();
                    }
                }
                return _emailsubject;
            }
            set { _emailsubject = value; }
        }
        private string _replyfromaddress;
        public string GetReplyFromAddress
        {
            get
            {
                _replyfromaddress = string.Empty;
                if (Settings.Contains("AutoReplyFromAddress"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["AutoReplyFromAddress"].ToString()))
                    {
                        _replyfromaddress = Settings["AutoReplyFromAddress"].ToString();
                    }
                }
                return _replyfromaddress;
            }
            set { _replyfromaddress = value; }
        }
        private string _bccaddress;
        public string GetBccAddress
        {
            get
            {
                _bccaddress = string.Empty;
                if (Settings.Contains("BccAddress"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["BccAddress"].ToString()))
                    {
                        _bccaddress = Settings["BccAddress"].ToString();
                    }
                }

                return _bccaddress;
            }
            set { _bccaddress = value; }
        }
        private bool _enablereply;
        public bool EnableReplyMail
        {
            get
            {
                _enablereply = false;
                if (Settings.Contains("SendReply"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SendReply"].ToString()))
                    {
                        bool.TryParse(Settings["SendReply"].ToString(), out _enablereply);
                    }
                }
                
                return _enablereply;
            }
            set { _enablereply = value; }
        }
        private string _replyemailtemplate;
        public string ReplyEmailTemplate
        {
            get
            {

                _replyemailtemplate = string.Empty;
                if (Settings.Contains("ReplyEmailTemplate"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ReplyEmailTemplate"].ToString()))
                    {
                        _replyemailtemplate = Settings["ReplyEmailTemplate"].ToString();
                    }
                }
                return _replyemailtemplate;
            }
            set { _replyemailtemplate = value; }
        }
        private bool _enablerecaptcha;
        public bool EnableGooglereCaptcha
        {
            get
            {
                _enablerecaptcha = false;
                if (Settings.Contains("EnableGooglereCaptcha"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EnableGooglereCaptcha"].ToString()))
                    {
                        bool.TryParse(Settings["EnableGooglereCaptcha"].ToString(), out _enablerecaptcha);
                    }
                }
                return _enablerecaptcha;
            }
            set { _enablerecaptcha = value; }
        }
        private string _recaptchaprivatekey;
        public string GetreCaptchaPrivateKey
        {
            get
            {
                _recaptchaprivatekey = string.Empty;

                if (Settings.Contains("reCaptchaPrivateKey"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaPrivateKey"].ToString()))
                    {
                        _recaptchaprivatekey = Settings["reCaptchaPrivateKey"].ToString();
                    }
                }
                return _recaptchaprivatekey;
            }
            set
            {
                _recaptchaprivatekey = value;
            }
        }
        private string _recaptchapublickey;
        public string GetreCaptchaPublicKey
        {
            get
            {
                _recaptchapublickey = string.Empty;

                if (Settings.Contains("reCaptchaPublicKey"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaPublicKey"].ToString()))
                    {
                        _recaptchapublickey = Settings["reCaptchaPublicKey"].ToString();
                    }
                }

                return _recaptchapublickey;
            }
            set { _recaptchapublickey = value; }
        }
        private string _recaptchatheme;
        public string GetreCaptchaTheme
        {
            get
            {
                _recaptchatheme = string.Empty;
                if (Settings.Contains("reCaptchaTheme"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaTheme"].ToString()))
                    {
                        _recaptchatheme = Settings["reCaptchaTheme"].ToString();
                    }
                }

                else
                {
                    _recaptchatheme = "Blackglass";
                }

                return _recaptchatheme;
            }
            set { _recaptchatheme = value; }
        }
        public string DefaultEmailRegex()
        {
            return @"[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}";
        }
        private string _emailregex;
        public string RegexEmail
        {
            get
            {
                _emailregex = string.Empty;


                if (Settings.Contains("RegexEmail"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["RegexEmail"].ToString()))
                    {
                        _emailregex = Settings["RegexEmail"].ToString();
                    }
                    else
                    {
                        _emailregex = DefaultEmailRegex();
                    }
                }
                else
                {
                    _emailregex = DefaultEmailRegex();
                }
                
                return _emailregex;
            }
            set { _emailregex = value; }
        }
        private bool _namefield;
        public bool ValidateNameField
        {
            get
            {
                _namefield = false;

                if (Settings.Contains("NameRequired"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["NameRequired"].ToString()))
                    {
                        bool.TryParse(Settings["NameRequired"].ToString(), out _namefield);
                    }
                }
                return _namefield;
                
               
            }
            set { _namefield = value; }
        }
        private bool _surnamefield;
        public bool ValidateSurnameField
        {
            get
            {
                _surnamefield = false;
                if (Settings.Contains("SurnameRequired"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SurnameRequired"].ToString()))
                    {
                        bool.TryParse(Settings["SurnameRequired"].ToString(), out _surnamefield);
                    }
                }
                
                return _surnamefield;
            }
            set { _surnamefield = value; }
        }
        private bool _contactnumber;
        public bool ValidateContactNumber
        {
            get
            {
                _contactnumber = false;
                if (Settings.Contains("ContactRequired"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ContactRequired"].ToString()))
                    {
                        bool.TryParse(Settings["ContactRequired"].ToString(), out _contactnumber);
                    }
                }
                
                return _contactnumber;
            }
            set { _contactnumber = value; }
        }
        private bool _messagevalidate;
        public bool ValidateMessageField
        {
            get
            {
                _messagevalidate = false;
                if (Settings.Contains("MessageRequired"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["MessageRequired"].ToString()))
                    {
                        bool.TryParse(Settings["MessageRequired"].ToString(), out _messagevalidate);
                    }
                }
                return _messagevalidate;
            }
            set { _messagevalidate = value; }
        }
       
        
        private string _blankrecaptcha;
        public string BlankRecaptcha
        {
            get
            {
                _blankrecaptcha = string.Empty;
                if (Settings.Contains("reCaptchaThemeblank"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaThemeblank"].ToString()))
                    {
                        _blankrecaptcha = Settings["reCaptchaThemeblank"].ToString();
                    }
                   
                }

                return _blankrecaptcha;
            }
            set { _blankrecaptcha = value; }
        }
        private string _incorrectcaptcha;
        public string IncorrectCaptcha
        {
            get
            {
                _incorrectcaptcha = string.Empty;

                if (Settings.Contains("reCaptchaThemeincorret"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaThemeincorret"].ToString()))
                    {
                        _incorrectcaptcha = Settings["reCaptchaThemeincorret"].ToString();
                    }

                }
                
                return _incorrectcaptcha;
            }
            set { _incorrectcaptcha = value; }
        }
        private string _nameerror;

        public string NameError
        {
            get
            {

                _nameerror = string.Empty;
                if (Settings.Contains("NameMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["NameMSG"].ToString()))
                    {
                        _nameerror = Settings["NameMSG"].ToString();
                    }

                }
                
                return _nameerror;
            }
            set { _nameerror = value; }
        }

        private string _surnameerror;

        public string SurnameError
        {
            get
            {
                _surnameerror = string.Empty;

                if (Settings.Contains("SurnameMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SurnameMSG"].ToString()))
                    {
                        _surnameerror = Settings["SurnameMSG"].ToString();
                    }

                }
                return _surnameerror;
            }
            set { _surnameerror = value; }
        }

        private string _contacterror;

        public string ContactError
        {
            get
            {
                _contacterror = string.Empty;


                if (Settings.Contains("ContactMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ContactMSG"].ToString()))
                    {
                        _contacterror = Settings["ContactMSG"].ToString();
                    }

                }
                return _contacterror;
            }
            set { _contacterror = value; }
        }

        private string _messageerror;

        public string MessageError
        {
            get
            {
                _messageerror = string.Empty;
                if (Settings.Contains("MessageMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["MessageMSG"].ToString()))
                    {
                        _messageerror = Settings["MessageMSG"].ToString();
                    }

                }
                return _messageerror;
            }
            set { _messageerror = value; }
        }

        private string _emailerror;

        public string EmailErrorMSG
        {
            get
            {

                _emailerror = string.Empty;
                if (Settings.Contains("EmailMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EmailMSG"].ToString()))
                    {
                        _emailerror = Settings["EmailMSG"].ToString();
                    }

                }
                
                return _emailerror;
            }
            set { _emailerror = value; }
        }


        private bool _profanitycheck;

        public bool ProfanityCheck
        {
            get
            {
                _profanitycheck = false;

                if (Settings.Contains("EnableProfanity"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EnableProfanity"].ToString()))
                    {
                        bool.TryParse(Settings["EnableProfanity"].ToString(), out _profanitycheck);
                    }
                }

                return _profanitycheck;
            }
            set { _profanitycheck = value; }
        }

        private string _profanitymsg;

        public string ProfanityMSG
        {
            get
            {
                _profanitymsg = string.Empty;
                if (Settings.Contains("ProfanityMessage"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ProfanityMessage"].ToString()))
                    {
                        _profanitymsg = Settings["ProfanityMessage"].ToString();
                    }

                }

                return _profanitymsg;
            }
            set { _profanitymsg = value; }
        }

        private string _emailsentok;

        public string EmailSentOK
        {
            get
            {
                _emailsentok = string.Empty;

                if (Settings.Contains("EMAILSENT"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EMAILSENT"].ToString()))
                    {
                        _emailsentok = Settings["EMAILSENT"].ToString();
                    }

                }
                
                return _emailsentok;
            }
            set { _emailsentok = value; }
        }


        private string _emailnotsent;

        public string EmailNotSent
        {
            get
            {
                _emailnotsent = string.Empty;
                if (Settings.Contains("EMAILNOTSENT"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EMAILNOTSENT"].ToString()))
                    {
                        _emailnotsent = Settings["EMAILNOTSENT"].ToString();
                    }

                }
                
                return _emailnotsent;
            }
            set { _emailnotsent = value; }
        }

        private string _autoreplyemailsubjecy;

        public string AutoReplyEmailSubject
        {
            get
            {
                _autoreplyemailsubjecy = string.Empty;

                if (Settings.Contains("AutoReplySubject"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["AutoReplySubject"].ToString()))
                    {
                        _autoreplyemailsubjecy = Settings["AutoReplySubject"].ToString();
                    }

                }
                
                return _autoreplyemailsubjecy;
            }
            set { _autoreplyemailsubjecy = value; }
        }
        
        
        #region Base Method Implementations

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadSettings loads the settings from the Database and displays them
        /// </summary>
        /// -----------------------------------------------------------------------------
        public override void LoadSettings()
        {
            yesitdid.Visible = false;
            noitdidnt.Visible = false;

            try
            {
                if (Page.IsPostBack == false)
                {
                    txtSmtpServer.Text = SMTPServerSettings;
                    chkusednn.Checked = UseDnnSettings;
                    txtsmtpusername.Text = SmtpUsername;
                    txtsmtppassword.Text = PasswordEncrypter.Decrypt(SmtpPassword);
                    txtsmtpport.Text = SmtpPortnum;
                    txttoaddress.Text = GetToAddress;
                    txtfromaddress.Text = GetFromAddress;
                    txtreplyfrom.Text = GetReplyFromAddress;
                    chkusereply.Checked = EnableReplyMail;
                    txtbccaddress.Text = GetBccAddress;
                    txtEmailSubject.Text = GetEmailsubject;
                    txtReplyEmail.Text = ReplyEmailTemplate;
                    ChkEnableRecaptcha.Checked = EnableGooglereCaptcha;
                    txtprivateKey.Text = GetreCaptchaPrivateKey;
                    txtpublickey.Text = GetreCaptchaPublicKey;
                    RecaptchaThemeDDL.Items.FindByValue(GetreCaptchaTheme).Selected = true;
                    NameField.Checked = ValidateNameField;
                    SurnameField.Checked = ValidateSurnameField;
                    chkContactNumberField.Checked = ValidateContactNumber;
                    chkMessageField.Checked = ValidateMessageField;
                    txtemailvalidationregex.Text = RegexEmail;
                    txtincorectcaptcha.Text = IncorrectCaptcha;
                    txtblankcaptcha.Text = BlankRecaptcha;
                    namemsg.Text = NameError;
                    surnamemsg.Text = SurnameError;
                    contmsg.Text = ContactError;
                    messagemsg.Text = MessageError;
                    EmailError.Text = EmailErrorMSG;
                    chkprofanity.Checked = ProfanityCheck;
                    txtprofanitymsg.Text = ProfanityMSG;
                    txtemailsent.Text = EmailSentOK;
                    txtemailerror.Text = EmailNotSent;
                    txtautoreplysubject.Text = AutoReplyEmailSubject;

                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// UpdateSettings saves the modified settings to the Database
        /// </summary>
        /// -----------------------------------------------------------------------------
        public override void UpdateSettings()
        {
            var encPass = new PasswordEncrypter();
            try
            {
                
                var modules = new ModuleController();
                /********************************************
                 * Save Contact Form SMTP Settings    
                 *******************************************/
                modules.UpdateModuleSetting(ModuleId, "DNNSMTPServer", chkusednn.Checked.ToString());
                modules.UpdateModuleSetting(ModuleId, "SMTPServer", txtSmtpServer.Text);
                modules.UpdateModuleSetting(ModuleId, "SMTPPort", txtsmtpport.Text);
                modules.UpdateModuleSetting(ModuleId, "SMTPUsername", txtsmtpusername.Text);
                modules.UpdateModuleSetting(ModuleId, "SMTPPassword", PasswordEncrypter.Encrypt(txtsmtppassword.Text));
                modules.UpdateModuleSetting(ModuleId, "EMAILSENT", txtemailsent.Text);
                modules.UpdateModuleSetting(ModuleId, "EMAILNOTSENT", txtemailerror.Text);

                /********************************************
                * Save Contact Form SMTP Settings  END  
                *******************************************/

                /********************************************
                * Save Contact Form Email Settings    
                *******************************************/
                modules.UpdateModuleSetting(ModuleId, "ToAddress", txttoaddress.Text);
                modules.UpdateModuleSetting(ModuleId, "FromAddress", txtfromaddress.Text);
                modules.UpdateModuleSetting(ModuleId, "AutoReplyFromAddress", txtreplyfrom.Text);
                modules.UpdateModuleSetting(ModuleId, "BccAddress", txtbccaddress.Text);
                modules.UpdateModuleSetting(ModuleId, "Subject", txtEmailSubject.Text);
                modules.UpdateModuleSetting(ModuleId, "AutoReplySubject", txtautoreplysubject.Text);
                /********************************************
                * Save Contact Form Email Settings END
                *******************************************/

                /********************************************
                * Save Contact Form Reply Template     
                *******************************************/
                modules.UpdateModuleSetting(ModuleId, "SendReply", chkusereply.Checked.ToString());
                modules.UpdateModuleSetting(ModuleId, "ReplyEmailTemplate", txtReplyEmail.Text);
                /********************************************
                * Save Contact Form Reply Template END    
                *******************************************/

                /********************************************
                * Save Contact Form Validation      
                *******************************************/
                modules.UpdateModuleSetting(ModuleId, "NameRequired", NameField.Checked.ToString());
                modules.UpdateModuleSetting(ModuleId, "SurnameRequired", SurnameField.Checked.ToString());
                modules.UpdateModuleSetting(ModuleId, "ContactRequired", chkContactNumberField.Checked.ToString());
                modules.UpdateModuleSetting(ModuleId, "MessageRequired", chkMessageField.Checked.ToString());
                modules.UpdateModuleSetting(ModuleId, "RegexEmail", txtemailvalidationregex.Text);
                modules.UpdateModuleSetting(ModuleId, "NameMSG", namemsg.Text);
                modules.UpdateModuleSetting(ModuleId, "SurnameMSG", surnamemsg.Text);
                modules.UpdateModuleSetting(ModuleId, "ContactMSG", contmsg.Text);
                modules.UpdateModuleSetting(ModuleId, "MessageMSG", messagemsg.Text);
                modules.UpdateModuleSetting(ModuleId, "EmailMSG", EmailError.Text);
                modules.UpdateModuleSetting(ModuleId, "EnableProfanity", chkprofanity.Checked.ToString());
                modules.UpdateModuleSetting(ModuleId, "ProfanityMessage", txtprofanitymsg.Text);

                /********************************************
                * Save Contact Form Validation  END    
                *******************************************/

                /********************************************
                * Save Contact Form Google reCaptcha Settings   
               *******************************************/
                modules.UpdateModuleSetting(ModuleId, "EnableGooglereCaptcha", ChkEnableRecaptcha.Checked.ToString());
                modules.UpdateModuleSetting(ModuleId, "reCaptchaPublicKey", txtpublickey.Text);
                modules.UpdateModuleSetting(ModuleId, "reCaptchaPrivateKey", txtprivateKey.Text);
                modules.UpdateModuleSetting(ModuleId, "reCaptchaTheme", RecaptchaThemeDDL.SelectedItem.Text);
                modules.UpdateModuleSetting(ModuleId, "reCaptchaThemeblank", txtblankcaptcha.Text);
                modules.UpdateModuleSetting(ModuleId, "reCaptchaThemeincorret", txtincorectcaptcha.Text);
                /********************************************
                * Save Contact Form Google reCaptcha Settings  END    
                *******************************************/

            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        #endregion
        #region Test SMTP Settings
        protected void TestSMTPSettings_Click(object sender, EventArgs e)
        {
            if (chkusednn.Checked)
            {
                try
                {
                    DotNetNuke.Services.Mail.Mail.SendEmail(smtpuser.Text, smtpuser.Text, "Test Email",
                                                        "This is a test email");
                    yesitdid.Visible = true;
                    noitdidnt.Visible = false;
                }
                catch (Exception)
                {
                    noitdidnt.Visible = true;
                    yesitdid.Visible = false;
                }

            }
            else
            {
                try
                {
                    MailMessage mail = new MailMessage();
                    mail.Subject = "Test Email";
                    mail.To.Add(txttestemail.Text);
                    MailAddress FromA = new MailAddress(txtsmtpusername.Text);
                    mail.From = FromA;
                    mail.Body = "This is a test email";
                    SmtpClient SmtpMail = new SmtpClient(txtSmtpServer.Text);
                    SmtpMail.Port = Convert.ToInt32(txtsmtpport.Text);
                    SmtpMail.Credentials = new System.Net.NetworkCredential(txtsmtpusername.Text, txtsmtppassword.Text);
                    SmtpMail.Send(mail);
                    mail.Dispose();
                    yesitdid.Visible = true;
                    noitdidnt.Visible = false;
                }
                catch (Exception)
                {
                    noitdidnt.Visible = true;
                    yesitdid.Visible = false;
                }
            }
        }
        #endregion

        protected void defaultregex_Click(object sender, EventArgs e)
        {
            txtemailvalidationregex.Text = DefaultEmailRegex();
        }
    }
}